home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gchess40.lha / gnuchess4.0p62 / src / fen2gnu.c < prev    next >
C/C++ Source or Header  |  1993-06-22  |  2KB  |  98 lines

  1. #include <stdio.h>
  2. #include <strings.h>
  3. /* convert fen notation to gnu save format */
  4. char            b[8][8];
  5. char            fn[12],*color;
  6. int             i, j, k, l;
  7. int             r, c;
  8. int        eps;
  9. char           *p, *q;
  10. FILE           *F, *O;
  11. int             wq, wk, bq, bk;
  12. char            in[128];
  13. /*
  14. /*        fen2gnu fen-file > outfile
  15. /*
  16. main(argc,argv)
  17. int argc;
  18. char *argv[];
  19. {
  20.     k = 1;
  21.     F = fopen(argv[1], "r");
  22.     while (fgets(in, 128, F) != NULL) {
  23.         if (strncmp("svfe", in, 4) == 0) {
  24.             wq = wk = bq = bk = 10;
  25.             for (i = 0; i < 8; i++) {
  26.                 for (j = 0; j < 8; j++) {
  27.                     b[i][j] = '.';
  28.                 }
  29.             }
  30.             p = &in[5];
  31.             r = 0;
  32.             c = 0;
  33.             while (*p != ' ') {
  34.                 if (isdigit(*p)) {
  35.                     c += (*p - '0');
  36.                 } else if (*p == '/') {
  37.                     r++;
  38.                     c = 0;
  39.                 } else {
  40.                     if(isupper(*p))*p = tolower(*p);
  41.                     else *p = toupper(*p);
  42.                     b[r][c] = *p;
  43.                     c++;
  44.                 }
  45.                 p++;
  46.  
  47.             }
  48.             p++;
  49.             if(*p == 'W') color = "White"; else color = "Black";
  50.             p += 2;
  51.             if (*p == 'K') {
  52.                 wk = 0;
  53.                 p++;
  54.             }
  55.             if (*p == 'Q') {
  56.                 wq = 0;
  57.                 p++;
  58.             }
  59.             if (*p == 'k') {
  60.                 bk = 0;
  61.                 p++;
  62.             }
  63.             if (*p == 'q') {
  64.                 bq = 0;
  65.                 p++;
  66.             }
  67.             while (*p != ' ')
  68.                 p++;
  69.             p++;
  70.             q = p;
  71.             while (*q != ' ')
  72.                 q++;
  73.             *q = '\0';
  74.             if(*p == 'n')eps = -1; else eps = (*p -'a')*8 + *(p+1)-'0';
  75.  
  76.         } else if (strncmp("srch", in, 4) == 0) {
  77.             sprintf(fn, "bk%03d", k);
  78.             k++;
  79.             O = fopen(fn, "w");
  80.             fprintf(O, "White computer Black Human 1 eps %d # To move %s correct move %sCastled White false Black false # ep %s\nTimeControl 0 Operator Time 0\nWhite Clock 0000 Moves 0\nBlack Clock 0000 Moves 0\n\n", eps,color,&in[5], p);
  81.             for (r = 0; r < 8; r++) {
  82.                 fprintf(O, "%c ", '0' + r);
  83.                 for (c = 0; c < 8; c++) {
  84.                     fprintf(O, "%c", b[r][c]);
  85.                 }
  86.                 if (r == 0)
  87.                     fprintf(O, " %d 10 10 10 %d 10 10 %d\n", bq, ((bq + bk) > 10) ? 10 : 0, bk);
  88.                 else if (r == 7)
  89.                     fprintf(O, " %d 10 10 10 %d 10 10 %d\n", wq, ((wq + wk) > 10) ? 10 : 0, wk);
  90.                 else
  91.                     fprintf(O, " 10 10 10 10 10 10 10 10\n");
  92.             }
  93.             fprintf(O, "  abcdefgh\n\nmove  score depth  nodes  time flags capture color\n");
  94.             fclose(O);
  95.         }
  96.     }
  97. }
  98.